﻿<%@ Page Language="C#" MasterPageFile="~/Admin/Admin.Master" AutoEventWireup="true" CodeBehind="EditDetailTemplate.aspx.cs" Inherits="Cms.Web.UI.Admin.EditDetailTemplate" ValidateRequest="false" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script type="text/javascript" src="Admin/js/jquery-ui-1.8.15.custom.min.js"></script>    
    <script type="text/javascript" src="Admin/js/jquery-timepicker-addon.js"></script>    
    <script language="javascript" type="text/javascript" src="Admin/Js/Edit.js"></script>
    <script language="javascript" type="text/javascript" src="Admin/edit_area/edit_area_loader.js"></script>
    <script language="javascript" type="text/javascript" src="Admin/Js/cms.date.js"></script>
    <script language="javascript" type="text/javascript">
        //<![CDATA[
        editAreaLoader.init({
            id: "txtCode",
	        syntax: "html",
	        start_highlight: true,
	        allow_resize: "no",
	        allow_toggle: false,
	        toolbar: "undo,redo,change_smooth_selection,reset_highlight,highlight,syntax_selection",
	        word_wrap: true,
	        replace_tab_by_spaces: 4
	    });
        
	    function updateCode() {
	        txtCode = document.getElementById("txtCode");
	        txtCode.value = editAreaLoader.getValue("txtCode");
	        document.getElementById("ctl00_body_hidCode").value = txtCode.value;
	    }

	    function setCodeEditorHeight() {
	        var viewportHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
	        var codeContainer = document.getElementById("codeContainer");
	        var height = viewportHeight - iLib.Pos.FindY(codeContainer) - 65;
	        height = height < 100 ? 100 : height;
	        codeContainer.style.height = height + "px";
	    }

	    function updatePanels(tab) {
	        var pnlProperties = document.getElementById("ctl00_body_pnlProperties");
	        var width = pnlProperties.offsetWidth;
	        pnlProperties.style.position = "absolute";
	        pnlProperties.style.left = -10000 + "px";
	        pnlProperties.style.width = width + "px";
	        pnlProperties.style.top = "0px";
	        var pnlContent = document.getElementById("ctl00_body_pnlContent");
	        pnlContent.style.display = "none";
	        switch (tab) {
	            case "properties":
	                pnlProperties.style.position = "";
	                pnlProperties.style.width = "100%";
	                pnlProperties.style.left = "0px";
	                break;
	            case "content":
	                pnlContent.style.display = "";
	                break;
	        }
	    }

	    var txtName;
	    var txtDescription;
	    var ddlPreferredMasterTemplates;
        var txtCode;
        var originalName;
        var originalDescription;
        var originalPreferredMasterTemplate;
	    var originalCode;
	    
	    function init() {
	        setCodeEditorHeight();
	        txtName = document.getElementById("ctl00_body_txtName");
	        txtDescription = document.getElementById("ctl00_body_txtDescription");
	        ddlPreferredMasterTemplates = document.getElementById("ctl00_body_ddlPreferredMasterTemplates");
	        txtCode = document.getElementById("txtCode");
	        txtCode.value = document.getElementById("ctl00_body_hidCode").value;
	        originalName = txtName.value;
	        originalDescription = txtDescription.value;
	        originalPreferredMasterTemplate = ddlPreferredMasterTemplates[ddlPreferredMasterTemplates.selectedIndex].value;
	        originalCode = txtCode.value;
	    }

	    function isDirty() {
	        var value = originalName == "" || originalName != txtName.value || 
                            originalDescription != txtDescription.value || 
                            originalCode != txtCode.value ||
	                        originalPreferredMasterTemplate != ddlPreferredMasterTemplates[ddlPreferredMasterTemplates.selectedIndex].value;
	        document.getElementById("ctl00_tabs_hidIsDirty").value = value;
	        return value;
	    }

	    function breakContentLink(areaID, contentType) {
	        document.getElementById("ctl00_tabs_hidBreakLinkAreaID").value = areaID;
	        document.getElementById("ctl00_tabs_hidBreakLinkContentType").value = contentType;
	        document.getElementById("ctl00_tabs_btnTriggerBreakContentLinkConfirmation").click();
	    }

	    function breakContentLinkCallback(status) {
	        if (status != "ok")
	            return;
	        cms.Edit.ShowTabOverlays();
	        document.getElementById("ctl00_tabs_btnBreakContentLink").click();
	    }

	    function initInlineDateTimePicker() {
	        var div = document.getElementById("datetimepicker");
	        var hid = document.getElementById("ctl00_body_hidScheduledPublishing");
	        setupInlineDatePicker(div, hid);
	        $(div).datetimepicker('setDate', (new Date()));
	    }

	    function schedulePublishingCallback(status) {
	        var hid = document.getElementById("ctl00_body_hidScheduledPublishing");
	        if (status != 'ok')
	            return;
	        cms.Edit.ShowTabOverlays();
	        document.getElementById("ctl00_body_btnSchedulePublishing").click();
	    }
	    //]]>
    </script>
    <link type="text/css" href="Admin/css/jquery-ui-1.8.16.custom.css" rel="Stylesheet" />	
    <link type="text/css" href="Admin/css/DateTimePicker.css" rel="Stylesheet" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="buttons" runat="server">
    <asp:LinkButton ID="lbSaveAndReturn" runat="server" OnClick="lbSaveAndReturn_Click" CssClass="orangeButton" OnClientClick="updateCode(); isDirty();"><span><span><img src="Admin/Img/icons/disk_go.png" alt="" /><span><cms:LocalizedLiteral ID="llSaveAndReturn" runat="server" /></span></span></span></asp:LinkButton>
    <asp:LinkButton ID="lbSave" runat="server" OnClick="lbSave_Click" CssClass="orangeButton" OnClientClick="updateCode(); isDirty();"><span><span><img src="Admin/Img/icons/disk.png" alt="" /><span><cms:LocalizedLiteral ID="llSave" runat="server" /></span></span></span></asp:LinkButton>
    <a href="Admin/DetailTemplates.aspx" class="orangeButton"><span><span><img src="Admin/Img/icons/delete.png" alt="" /><span><cms:LocalizedLiteral ID="llCancel" runat="server" /></span></span></span></a>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="tabs" runat="server">
    <asp:UpdatePanel ID="upnlTabs" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">
        <ContentTemplate>
            <cms:AdminTabStrip ID="tabStrip" runat="server" SelectedValue="properties" OnChange="tabStrip_Click">
                <cms:AdminTabItem ID="tiProperties" runat="server" value="properties" EnabledImage="Admin/Img/icons/layout_detail_gear.png"><cms:LocalizedLiteral ID="llPropertiesTab" runat="server" /></cms:AdminTabItem>
                <cms:AdminTabItem ID="tiContent" runat="server" value="content" EnabledImage="Admin/Img/icons/page_white_edit.png"><cms:LocalizedLiteral ID="llContentTab" runat="server" /></cms:AdminTabItem>
            </cms:AdminTabStrip>
            <input type="hidden" id="hidIsDirty" runat="server" />
            <input type="hidden" id="hidBreakLinkAreaID" runat="server" />
            <input type="hidden" id="hidBreakLinkContentType" runat="server" />
            <div style="position: absolute; top: 0px; left: -10000px;">
                <asp:Button ID="btnTriggerBreakContentLinkConfirmation" runat="server" OnClick="btnTriggerBreakContentLinkConfirmation_Click" Text="Break content link confirmation trigger" />
                <asp:Button ID="btnBreakContentLink" runat="server" OnClick="btnBreakContentLink_Click" Text="Break content link" />
            </div>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="body" runat="server">
    <asp:Literal ID="litIcon" runat="server" Visible="false" Text="Admin/Img/Icons/layout_detail_edit.png" />

    <asp:Panel ID="pnlProperties" runat="server" CssClass="pnlTab">
        <asp:UpdatePanel ID="upnlProperties" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
            <ContentTemplate>
                <table class="editForm">
                    <tr>
                        <td><cms:LocalizedLiteral ID="llName" runat="server" />:</td>
                        <td><asp:TextBox ID="txtName" runat="server" Width="500" /></td>
                    </tr>
                    <tr>
                        <td><cms:LocalizedLiteral ID="llDescription" runat="server" />:</td>
                        <td><asp:TextBox ID="txtDescription" runat="server" TextMode="MultiLine" Width="500" Rows="3" /></td>
                    </tr>
                    <tr>
                        <td><cms:LocalizedLiteral ID="llPreferredMasterTemplate" runat="server" /></td>
                        <td><asp:DropDownList ID="ddlPreferredMasterTemplates" runat="server" /></td>
                    </tr>
                </table>
                <input type="hidden" id="hidCode" runat="server" />
            </ContentTemplate>
        </asp:UpdatePanel>
        <br />
        <div id="codeContainer" style="height: 400px;">
            <textarea id="txtCode" cols="10" rows="10" style="width: 100%; height: 100%;"></textarea>
        </div>
        <div class="pnlTabOverlay"></div>
    </asp:Panel>
    <asp:Panel ID="pnlContent" runat="server" CssClass="pnlTab">
        <asp:UpdatePanel ID="upnlContent" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
            <ContentTemplate>
                <table class="editForm">
                    <tr>
                        <td><cms:LocalizedLiteral ID="llLocale" runat="server" />:</td>
                        <td><asp:DropDownList ID="ddlLocales" runat="server" OnSelectedIndexChanged="ddlLocales_IndexChanged" AutoPostBack="true" /></td>
                        <td><cms:LocalizedLiteral ID="llVersion" runat="server" />:</td>
                        <td><asp:DropDownList ID="ddlVersions" runat="server" OnSelectedIndexChanged="ddlVersions_IndexChanged" AutoPostBack="true" /></td>
                        <td><asp:LinkButton ID="lbPublish" runat="server" OnClick="lbPublish_Click" CssClass="orangeButton"><span id="s1" runat="server"><span id="s2" runat="server"><img src="Admin/Img/icons/page_white_go.png" alt="" id="imgPublish" runat="server" /><span id="s3" runat="server"><cms:LocalizedLiteral ID="llPublish" runat="server" /></span></span></span></asp:LinkButton></td>
                        <td><a ID="hlPublishLater" runat="server" Class="orangeButton" href="javascript:void(0);"><span id="Span1" runat="server"><span id="Span2" runat="server"><img src="Admin/Img/icons/clock.png" alt="" id="img1" runat="server" /><span id="Span3" runat="server"><cms:LocalizedLiteral ID="llPublishLater" runat="server" /></span></span></span></a></td>
                    </tr>
                </table>
                <table class="editForm">
                    <tr>
                        <td><cms:LocalizedLiteral ID="llPublishedVersion" runat="server" />: <asp:LinkButton ID="lbSelectPublishedVersion" runat="server" OnClick="lbSelectPublishedVersion_Click" /><cms:LocalizedLiteral ID="llNoVersionPublished" runat="server" /></td>
                    </tr>
                </table>
                <table class="editForm">
                    <tr>
                        <td><cms:LocalizedLiteral ID="llMasterTemplate" runat="server" />:</td>
                        <td><asp:DropDownList ID="ddlMasterTemplates" runat="server" OnSelectedIndexChanged="ddlMasterTemplates_IndexChanged" AutoPostBack="true" /></td>
                    </tr>
                </table>
                <asp:Panel ID="pnlScheduledPublishings" runat="server">
                    <span style="display: block; font-weight: bold; padding-left: 4px; padding-top: 6px; padding-bottom: 4px;">Schemalagda publiceringar</span>
                    <table>
                        <tr>
                            <td>Version</td>
                            <td>Tidpunkt</td>
                            <td>&nbsp;</td>
                        </tr>
                    <asp:Repeater ID="rpScheduledPublishings" runat="server" OnItemDataBound="rpScheduledPublishings_ItemDataBound">
                        <ItemTemplate>
                            <tr>
                                <td><asp:Literal ID="litVersion" runat="server" /></td>
                                <td><asp:Literal ID="litTimestamp" runat="server" /></td>
                                <td><asp:LinkButton ID="lbDeleteScheduledPublishing" runat="server" OnClick="lbDeleteScheduledPublishing_Click" OnClientClick="cms.Edit.ShowTabOverlays();"><cms:LocalizedLiteral ID="llDeleteScheduledPublishing" runat="server" /></asp:LinkButton></td>
                            </tr>
                        </ItemTemplate>
                    </asp:Repeater>
                    </table>
                </asp:Panel>
                <div class="sitePreviewContainer">
                    <div class="sitePreviewHeader"><cms:LocalizedLiteral ID="llPreviewHeader" runat="server" /></div>
                    <iframe id="ifrPreview" runat="server" frameborder="0" class="sitePreview" scrolling="no" height="300"></iframe>
                </div>
                <div id="schedulePublishing" style="position: absolute; top:80px; left: -10000px;">
                    <div style="margin-top: 10px;  margin-bottom: 10px;">
                        <div id="datetimepicker"></div>
                    </div>
                    <input id="hidScheduledPublishing" runat="server" type="hidden" />
                </div>
                <asp:Button ID="btnSchedulePublishing" runat="server" Text="SchedulePublishing" OnClick="btnSchedulePublishing_Click" style="position: absolute; top: 0px; left: -10000px;" />
            </ContentTemplate>
        </asp:UpdatePanel>
        <div class="pnlTabOverlay"></div>
    </asp:Panel>

    <script type="text/javascript" language="javascript">
        //<![CDATA[
        iLib.Dom.AddListener(window, "load", init);
        cms.Ajax.Init();
        cms.Ajax.AddEndRequestHandler(cms.Edit.HideTabOverlays);
        //]]>
    </script>
</asp:Content>
